//
//  HCTarBarController.swift
//  新浪微博
//
//  Created by fanhoucheng on 16/9/22.
//  Copyright © 2016年 fanhoucheng. All rights reserved.
//

import UIKit

class HCTarBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //创建tarbar,然后赋值给当前tarbar
        let customTarBar = HCTarBar()
        
        //KVC赋值
        self.setValue(customTarBar, forKey: "tabBar")

        addChildViewControllers()
        
    }
    
    func addChildViewControllers() {
        addChildViewController(vc:HCHomeTableViewController(), imageName:"tabbar_home", title:"首页")
        addChildViewController(vc:HCMessageTableViewController(), imageName:"tabbar_message_center", title:"消息")
        addChildViewController(vc:HCDiscoverTableViewController(), imageName:"tabbar_discover", title:"发现")
        addChildViewController(vc:HCProfileTableViewController(), imageName:"tabbar_profile", title:"我")
    }

    func addChildViewController(vc:UIViewController, imageName:String,title:String) {
        
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        
        //标题
        vc.tabBarItem.title = title
        vc.navigationItem.title = title
        
        //标题颜色
        vc.navigationController?.navigationBar.backgroundColor = UIColor.darkGray
        
        //字体
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: UIControlState.normal)
        
        //设置徽标颜色和数量(徽标:就是右上角的多少条消息)
        //vc.tabBarItem.badgeColor = UIColor.purple
        //vc.tabBarItem.badgeValue = nil
        
        let nav = HCBaseNavController(rootViewController: vc)
        
        addChildViewController(nav)
    }
    
}
